package com.hyving.summer.picmatch.strategy;

import java.awt.*;
import java.awt.image.BufferedImage;

public class SimpleStrategy {



    public static int[] getData(BufferedImage img) {
        try {
            BufferedImage slt = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
            //slt.getGraphics().drawImage(img, 0, 0, img.getWidth(), img.getHeight(), 0,105,img.getWidth(),img.getHeight(),null);
            slt.getGraphics().drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null);

            // ImageIO.write(slt,"jpeg",new File("slt.jpg"));
            int[] data = new int[256];
            for (int x = 0; x < slt.getWidth(); x++) {
                for (int y = 0; y < slt.getHeight(); y++) {
                    int rgb = slt.getRGB(x, y);
                    Color myColor = new Color(rgb);
                    int r = myColor.getRed();
                    int g = myColor.getGreen();
                    int b = myColor.getBlue();
                    data[(r + g + b) / 3]++;
                }
            }
            // data 就是所谓图形学当中的直方图的概念
            return data;
        } catch (Exception exception) {
            return null;
        }
    }
}
